﻿    <%@ Page Title="" Language="C#" MasterPageFile="~/back/Site.master" AutoEventWireup="true"
    CodeFile="ViewProperties.aspx.cs" Inherits="back_ViewProperties" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <script src="../js/jquery-1.8.1.min.js" type="text/javascript"> </script>
    <script src="../js/bootstrap-modal.js" type="text/javascript"></script>
    <script type="text/javascript">
        function lanchBuilderPopUp(propertyId) {
            //$("#MainContent_drpMode").val('');
            //$("#MainContent_txtAmount").val('');

            $("#MainContent_txtBPropertyId").val(propertyId);
            $("#myModalBuilder").modal('show');
        }
        function lanchArchitectPopUp(propertyId) {
            //$("#MainContent_drpMode").val('');
            //$("#MainContent_txtAmount").val('');

            $("#MainContent_txtAPropertyId").val(propertyId);
            $("#myModalArchitect").modal('show');
        }
        function assignBuilder(builderId) {
            $.ajax({
                type: "POST",
                url: "ViewProperties.aspx/assignBuilders",
                data: "{'propertyId': '" + $("#MainContent_txtBPropertyId").val() + "', 'builderId':'" + builderId + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    if (response.d == "OK") {
                        window.location.href = "ViewProperties.aspx";
                    }
                    else {
                        $("#MainContent_dvMessageBuilders").html("Something went wrong. Please try after some time.");
                    }
                },
                error: function (response) {

                }
            });
        }
        function assignArchitect(architectId) {
            $.ajax({
                type: "POST",
                url: "ViewProperties.aspx/assignArchitects",
                data: "{'propertyId': '" + $("#MainContent_txtAPropertyId").val() + "', 'architectId':'" + architectId + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    if (response.d == "OK") {
                        window.location.href = "ViewProperties.aspx";
                    }
                    else {
                        $("#MainContent_dvMessageBuilders").html("Something went wrong. Please try after some time.");
                    }
                },
                error: function (response) {

                }
            });
        }
    </script>

    <div class="page-header">
        <h1>
            View Properties</h1>
    </div>
    <div id="divRed" runat="server">
    </div>
    <div id="divGreen" runat="server">
    </div>
    <asp:GridView ID="grdProperties" runat="server" AutoGenerateColumns="False" Width="100%"
        CssClass="table table-striped table-bordered" OnRowDataBound="grdProperties_RowDataBound"
        PageSize="3" OnPageIndexChanging="grdProperties_PageIndexChanging" AllowPaging="true">
        <Columns>
            <asp:TemplateField HeaderText="Property Info">
                <ItemTemplate>
                    <asp:Label ID="hdnPropertyId" Style="display: none;" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
                    <asp:Label ID="lblUserId" Style="display: none;" runat="server" Text='<%#Eval("UserId") %>'></asp:Label>
                    <asp:Label ID="hdnBuilderId" Style="display: none;" runat="server" Text='<%#Eval("BuilderId") %>'></asp:Label>
                    <asp:Label ID="hdnArchitectId" Style="display: none;" runat="server" Text='<%#Eval("ArchitectId") %>'></asp:Label>
                    <span><strong>
                        <%# Eval("Name") %></strong><br />
                        <%# Eval("Address1") %>,<br />
                        <%# Eval("Address2") %>.<br />
                        <%# Eval("City") %>
                        <br />
                        <br />
                        <strong>Year Built:
                            <%# Eval("YearBuilt") %></strong>
                        <br />
                        <br />
                        <strong>Area in Sq.Mt:
                            <%# Eval("AreaSqMt") %></strong> </span>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description & Features">
                <ItemTemplate>
                    <span>Description:
                        <%# Eval("Description") %>
                        <br />
                        <br />
                        Features:
                        <%# Eval("Features") %>
                    </span>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Report">
                <ItemTemplate>
                    <asp:Label ID="lblReport" runat="server" Text='<%#Eval("Report") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Issue">
                <ItemTemplate>
                    <asp:Label ID="lblIssue" runat="server" Text='<%#Eval("Issue") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="User">
                <ItemTemplate>
                    <asp:Label ID="lblUser" runat="server"></asp:Label>
                    <hr />
                    <asp:Label ID="lblBuilder" runat="server"></asp:Label><hr />
                    <asp:Label ID="lblArchitect" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Actions">
                <ItemTemplate>
                    <%--<asp:Button ID="btnEdit" runat="server" CssClass="btn btn-info" Text="Edit" CommandName="EditArchitect"
                        OnClientClick="return confirm('Do you want to edit this content?')" />
                    &nbsp;&nbsp;
                    <asp:Button ID="btnDelete" runat="server" CssClass="btn btn-danger" Text="Delete"
                        CommandName="DeleteArchitect" OnClientClick="return confirm('Do you want to delete this content?')" />--%>
                    <asp:Button ID="btnBuilders" runat="server" CssClass="btn btn-info" Visible="false" Text="Assign Builder" />
                    <br /><br />
                    <asp:Button ID="btnArchitects" runat="server" CssClass="btn btn-info" Visible="false" Text="Assign Architect" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerSettings Position="TopAndBottom" />
        <PagerStyle CssClass="pagination" />
    </asp:GridView>
    <div class="modal fade" id="myModalArchitect" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;</button>
                    <h4 class="modal-title">
                        Architects</h4>
                </div>
                <div class="modal-body">
                    <div id="dvMessageArchitects" style="color: Red;" runat="server">
                    </div>
                    <input type="hidden" id="txtAPropertyId" runat="server" />
                    <center>
                        <asp:GridView ID="grdArchitects" runat="server" AutoGenerateColumns="false" BorderWidth="0" CssClass="table table-striped table-bordered">
                        <Columns>
                            <asp:BoundField HeaderText="Name" DataField="Firm" />
                            <asp:BoundField HeaderText="Property Location" DataField="PropertyLocation" />
                            <asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                    <a href="#" onclick='assignArchitect(<%#Eval("Id") %>);'>Select</a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    </center>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="myModalBuilder" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;</button>
                    <h4 class="modal-title">
                        Builders</h4>
                </div>
                <div class="modal-body">
                    <div id="dvMessageBuilders" style="color: Red;" runat="server">
                    </div>
                    <input type="hidden" id="txtBPropertyId" runat="server" />
                    <center>
                        <asp:GridView ID="grdBuilders" runat="server" AutoGenerateColumns="false" BorderWidth="0" CssClass="table table-striped table-bordered">
                        <Columns>
                            <asp:BoundField HeaderText="Name" DataField="Name" />
                            <asp:BoundField HeaderText="Property Location" DataField="PropertyLocation" />
                            <%--<asp:BoundField HeaderText="Head Quarters" DataField="HeadQuarter" />--%>
                            <asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                    <a href="#" onclick='assignBuilder(<%#Eval("Id") %>);'>Select</a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    </center>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
